import { nanoid } from 'nanoid'

export enum ComponentV2raySubscriptionLastUpdateState {
    NotRun = 'NotRun',
    Success = 'Success',
    Failed = 'Failed',
}

export const ComponentV2raySubscriptionLastUpdateStateNames: Record<ComponentV2raySubscriptionLastUpdateState, string> = {
    [ComponentV2raySubscriptionLastUpdateState.NotRun]: '未运行',
    [ComponentV2raySubscriptionLastUpdateState.Success]: '成功',
    [ComponentV2raySubscriptionLastUpdateState.Failed]: '失败',
}

export declare type ComponentV2raySubscription = {
    uuid: string
    name: string
    url: string
    enabled: boolean
    auto_update: boolean
    last_update_time: number
    last_update_state: ComponentV2raySubscriptionLastUpdateState
}

export function new_component_v2ray_subscription(): ComponentV2raySubscription {
    return {
        uuid: nanoid(),
        name: '',
        url: '',
        enabled: false,
        auto_update: false,
        last_update_time: 0,
        last_update_state: ComponentV2raySubscriptionLastUpdateState.NotRun,
    }
}
